# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 0:03
# @Author  : catherine
# @Email   : catherine_csq@163.com
# @File    : add_clue_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.clue_home_page import ClueHomePage


class AddCluePage(ClueHomePage):
    '''添加线索页面类'''
    url='http://192.168.189.1:8081/crm/index.php?m=leads&a=add'
    #定位器
    company_locator = (By.XPATH, '//*[@id="name"]')
    source_locator = (By.XPATH, '//*[@id="source"]')
    contacts_name_locator = (By.ID, 'contacts_name')
    position_locator = (By.ID, 'position')
    saltname_locator = (By.ID, 'saltname')
    mobile_locator = (By.ID, 'mobile')
    email_locator = (By.ID, 'email')
    save_locator = (By.XPATH, '//*[@id="form1"]/table/tfoot/tr/td/input[1]')
    nextstep_locator = (By.ID, 'nextstep')
    back_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(3)')
    add_in_clue_poll_locator=(By.ID,'remove')

    def click_add_in_clue_poll(self):
        '''将线索放到线索池'''
        self.driver.find_element(*self.add_in_clue_poll_locator).click()
        self.driver.switch_to.alert.accept()

    def input_company(self,companyname):
        '''添加公司名'''
        self.driver.find_element(*self.company_locator).send_keys(companyname)

    def input_source(self,source):
        '''添加来源'''
        source_list = Select(self.driver.find_element(*self.source_locator))
        source_list.select_by_visible_text(source)

    def input_contacts_name(self,contactname):
        '''添加联系人姓名'''
        self.driver.find_element(*self.contacts_name_locator).send_keys(contactname)

    def input_position(self,position):
        '''添加职位'''
        self.driver.find_element(*self.position_locator).send_keys(position)

    def input_saltname(self,saltname):
        '''添加尊称'''
        saltname_list = Select(self.driver.find_element(*self.saltname_locator))
        saltname_list.select_by_visible_text(saltname)

    def input_mobile(self,mobile):
        '''添加手机'''
        self.driver.find_element(*self.mobile_locator).send_keys(mobile)

    def input_email(self,email):
        '''添加邮箱'''
        self.driver.find_element(*self.email_locator).send_keys(email)

    def click_save_add_clue(self):
        '''保存新建'''
        self.driver.find_element(*self.save_locator).click()

    def input_nextstep(self,nextstep):
        '''添加联系内容'''
        self.driver.find_element(*self.nextstep_locator).send_keys(nextstep)

    def click_back(self):
        '''点击返回，从添加线索页回到线索主页'''
        self.driver.find_element(*self.back_locator).click()
